<?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 */

App::uses('Controller', 'Controller');

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package		app.Controller
 * @link		http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
 */
class AppController extends Controller {
    public $components = array('DebugKit.Toolbar','Paginator', 'Session', 'RequestHandler',  
                                       'Acl',
                                       'Auth'  => array(
                                                'loginRedirect' => array(
                                                    'controller' => 'bookings',
                                                    'action' => 'index'
                                                ),
                                                'logoutRedirect' => array(
                                                    'controller' => 'users',
                                                    'action' => 'login'
                                                ),
                                                'authorize' => array(
                                                    'Actions' => array('actionPath' => 'controllers')                                 
                                                ),    
                                                'loginAction' => array(
                                                    'controller' => 'users',
                                                    'action' => 'login'
                                                ),
                                           	'flash' => array(
                                                    'element' => 'alert',
                                                    'key' => 'auth',
                                                    'params' => array(
                                                            'plugin' => 'BoostCake',
                                                            'class' => 'alert-info'
                                                        )
                                                ),                                           
                                        )        
                              );
    
	public $helpers = array(
		'Session',
		'Html' => array('className' => 'BoostCake.BoostCakeHtml'),
		'Form' => array('className' => 'BoostCake.BoostCakeForm'),
		'Paginator' => array('className' => 'BoostCake.BoostCakePaginator'),
                'Nav',
              
	);
        
//Check if we only need JSON and Render the Event with the most wanted method.        
        public function beforeRender(){
            if ($this->RequestHandler->isAjax()){
                $this->autoRender = false;
                $this->autoLayout = false;
                Configure::write('debug', 0);
                if($this->RequestHandler->prefers() == 'json') {
                    die(json_encode($this->viewVars));
                }
                else {
                    $this->layout = 'ajax';
                }
            }
        }
    

}
